#include <stdlib.h>

#include <thread>
#include <iostream>
#include <chrono>

#include "metrics/utility/CPUMetricsBuilder.hpp"
#include "metrics/utility/MemMetricsBuilder.hpp"
#include "metrics/Counter.hpp"
#include "metrics/Builder.hpp"
#include "metrics/Histogram.hpp"
#include "metrics/ConsoleMetricReporter.hpp"

int main(int argc, char const *argv[])
{
    metrics::ConsoleMetricReporter reporter;
    auto registry = std::make_shared<metrics::MetricRegistry>();

    std::map<std::string, std::string> m{{"a", "b"}, {"c", "d"}};

    std::shared_ptr<metrics::Family<metrics::Counter>> counterFamily = metrics::BuildCounter().name("count_total").help("test").labels(m).metric_register(registry);
    std::shared_ptr<metrics::Counter> inputCount = counterFamily->add({{"direct", "input"}});
    std::shared_ptr<metrics::Counter> outputCount = counterFamily->add({{"direct", "output"}});

    metrics::BuildCPUMetrics().labels(m).metric_register(registry);
    metrics::BuildMemMetrics().labels(m).metric_register(registry);

    reporter.register_collectable(registry).interval(1, 0);

    std::thread th([&reporter]()
                   { reporter.start(); });

    for (size_t i = 0; i < 10; i++)
    {
        inputCount->increment(rand() % 50);
        outputCount->increment(rand() % 50);
        std::this_thread::sleep_for(std::chrono::seconds(1));
    }

    reporter.stop();
    th.join();
    return 0;
}
